<?php
namespace Model;

class verificationModel{
	
	/**
	 * @var $sessUserName
	 * @var $sessPassWord
	 */
	private static $sessUserName = "self::sessUserName";
	private static $sessPassWord = "self::sessPassWord";
	
	/**
	 * @return boolean
	 */
	public function verifyUserCredentials($userName, $passWord){
		if($userName == "User" && $passWord == "Pw"){
			return true;
		}
		else{
			return false;
		}
	}
	
	/**
	 * @return boolean
	 */
	public function verifyAdminCredentials($userName, $passWord){
		if($userName == "Admin" && $passWord == "Pw"){
			return true;
		}
		else{
			return false;
		}
	}
	
	/**
	 * @return boolean
	 * 
	 * @throws \Exception (If the admins input is not validated)
	 */
	public function verifyQuizInput($quizName, $numOfQs){
		if($this->validateQuizName($quizName) && $this->validateInteger($numOfQs)){
			return true;
		}
		else{
			throw new \Exception("Detta är inget giltigt Quiznamn!");
		}		
	}
	
	/**
	 * @param $string (A string to be checked for invalid input) 
	 * @return boolean (True if the string is validated)
	 * @throws \Exception (If the string is not validated)
	 */
	private function validateQuizName($string){
		if(strlen($string) >= 4 || strlen($string) <= 20 && $string != ""){
			$cleanString = strip_tags($string);
			if($string === $cleanString){
				if(preg_match('/\d/', $string) == 0){
					return true;
				}
			}
		}
		return false;
	}
	
	/**
	 * @param $string (A string to be checked for invalid input) 
	 * @return boolean (True if the string is validated)
	 * @throws \Exception (If the string is not validated)
	 */
	private function validateString($string){
		if(strlen($string) >= 0 || strlen($string) <= 100 && $string != ""){
			$cleanString = strip_tags($string);
			if($string === $cleanString){
				if(preg_match('/\d/', $string) == 0){
					return true;
				}
			}
		}
		throw new \Exception("Detta är inget giltigt quiznamn!");
	}
	
	/**
	 * @param $int (An integer to be validated)
	 * @return boolean (Wether or not the integer passed the validation)
	 */
	private function validateInteger($int){
		if($int != "" && is_numeric($int) && $int <= 5){
			return true;
		}
		return false;
	}
}
